#ifndef PLAYERMANAGER_H
#define PLAYERMANAGER_H

#include "../../Frame/Player.h"
#include "../../Frame/Message.h"
#include "../../Frame/DBStruct.h"
#include "../../Frame/Database.h"
#include "../../Frame/GlobalManager.h"
#include "RoleManager.h"
#include <map>

using namespace std;

class PlayerManager
{
	public:
		PlayerManager();
		~PlayerManager();

		bool Init(Database& _pDB);

		Player* GetPlayer(int _Playerid);
		Player* GetPlayerByFd(int _fd);

		int GetPlayerId(int _userId);
		bool isExist(int _userid);
		int Create(int _userId, int _roleCfgId, string _name, RoleManager* _pRoleMgr, GlobalManager* _pGlobalMgr);

		int GetValue(eGlobalKey _key);

		bool UpdateValue(eGlobalKey _key, int _value);

	protected:
	private:
		bool Cache(const tPlayer& _DB);

		map<int, int> m_fdIDMap; 						// <fd, playerId>映射登录和离线的时候 需要维护

		map<int, Player> m_DataMap; 					// <playerId, Player>

		map<int, int> m_userIdPlayerIdMap;				// <userId, playerId> 映射


		Database* m_pDB;

};

#endif // PLAYERMANAGER_H
